//
//  ScontractDetailViewModel.m
//  Jyxt
//
//  Created by 宫璞 on 2017/9/8.
//  Copyright © 2017年 DaLian Rental Housing Management. All rights reserved.
//

#import "ScontractDetailViewModel.h"
#import "NetTool.h"

@implementation ScontractDetailViewModel
+(instancetype)sharedInstance{
    static ScontractDetailViewModel *contractDetail;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        contractDetail = [[ScontractDetailViewModel alloc]init];
    });
    
    return contractDetail;
}


- (void)requestContractDetailWithUtoken:(NSString *)token id:(NSString *)Id success:(void (^)(NSArray *))success Fail:(BLOCK_SERVICE_REQUEST_FAIL)fail{
    [NetTool postWithUrl:APIURL(API_CONTRACTDETAIL) data:@{@"utoken":token,@"id":Id} onSuccess:^(NSDictionary *response) {
        NSMutableArray<McontractDetailModel *> *contractDetailArr = [[NSMutableArray alloc]init];
        McontractDetailModel *contractItem = [[McontractDetailModel alloc]init];
        
        contractItem.lessorName = response[@"data"][@"lessorName"];
        contractItem.lessorIdNo = response[@"data"][@"lessorIdNo"];
        contractItem.lessorMobile = response[@"data"][@"lessorMobile"];
        contractItem.lessorAddress = response[@"data"][@"lessorAddress"];
        contractItem.lessorBackupName = response[@"data"][@"lessorBackupName"];
        contractItem.lessorBackupTel = response[@"data"][@"lessorBackupTel"];
        
        contractItem.lesseeName = response[@"data"][@"lesseeName"];
        contractItem.lesseeIdNo = response[@"data"][@"lesseeIdNo"];
        contractItem.lesseeMobile = response[@"data"][@"lesseeMobile"];
        contractItem.lesseeAddress = response[@"data"][@"lesseeAddress"];
        contractItem.lesseeBackupName = response[@"data"][@"lesseeBackupName"];
        contractItem.lesseeBackupTel = response[@"data"][@"lesseeBackupTel"];
        
        contractItem.propertyType = response[@"data"][@"propertyType"];
        contractItem.rentalMode = response[@"data"][@"rentalMode"];
        contractItem.leaseDomain = response[@"data"][@"leaseDomain"];
        contractItem.houseStructure = response[@"data"][@"houseStructure"];
        
        contractItem.leaseTermYear = response[@"data"][@"leaseTermYear"];
        contractItem.leaseTermMonth = response[@"data"][@"leaseTermMonth"];
        contractItem.date = [NSString stringWithFormat:@"%@年%@个月",response[@"data"][@"leaseTermYear"],response[@"data"][@"leaseTermMonth"]];
        contractItem.startTime = response[@"data"][@"startTime"];
        contractItem.endTime = response[@"data"][@"endTime"];
        
        contractItem.monthlyRent = [response[@"data"][@"monthlyRent"] integerValue];
        contractItem.settlementCycle = response[@"data"][@"settlementCycle"];
        contractItem.depositAmt = [response[@"data"][@"depositAmt"] integerValue];
        
        contractItem.houseAddr = response[@"data"][@"houseAddr"];
        contractItem.name = [response[@"data"][@"houseUserList"] objectAtIndex:0][@"name"];
        contractItem.mobile = [response[@"data"][@"houseUserList"] objectAtIndex:0][@"mobile"];
        contractItem.idNo = [response[@"data"][@"houseUserList"] objectAtIndex:0][@"idNo"];
        
        [contractDetailArr addObject:contractItem];
        
        
        success(contractDetailArr);
    } onError:^(NSError *error) {
        fail(error);
    }];
}




@end
